package cn.iocoder.yudao.framework.business.basic.pojo.vo;

import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.MobileDesensitize;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  视图对象
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2024/06/11
 */
@Tag(name = "用户信息 VO")
@Data
public class UserSimpleVO implements VO {
    public static final UserSimpleVO ANONYMOUS = new UserSimpleVO();

    static {
        ANONYMOUS.setId(0L);
        ANONYMOUS.setPid(0L);
        ANONYMOUS.setNickname("匿名");
        ANONYMOUS.setAvatar("");
        ANONYMOUS.setNo("");
    }

    @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Long id;

    @Schema(description = "上级用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
    @JsonIgnore
    private Long pid;

    @Schema(description = "邀请码")
    private String no;

    @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "羡民")
    private String nickname;

    @Schema(description = "真实姓名", requiredMode = Schema.RequiredMode.REQUIRED, example = "李玉江")
    private String name;

    @Schema(description = "用户头像")
    private String avatar;

    @Schema(description = "用户性别", example = "1")
    private Integer sex;

    @Schema(description = "帐号状态：0-禁用、1-正常", example = "1")
    private Integer status;

    @Schema(description = "手机号", example = "15285116029")
    @MobileDesensitize(disable = "@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    private String mobile; // 手机号码为敏感的隐私数据，非管理员角色的话，避免明文返回给前端

    @Schema(description = "创建时间（注册时间）", requiredMode = Schema.RequiredMode.REQUIRED)
    private LocalDateTime createTime;

    @Schema(description = "展示名称：真名/手机号/昵称", example = "羡民")
    private String displayName;

    public String getDisplayName() {
        String n = getName();
        if (StrUtil.isNotBlank(n)) {
            return n;
        }
        String m = getMobile();
        if (StrUtil.isNotBlank(m)) {
            return DesensitizedUtil.mobilePhone(m);
        }
        return getNickname();
    }

}
